import React, { Component } from "react";
import { Form, Modal, Button, Input, Radio, message } from "antd";

const layout = {
  labelCol: {
    span: 8,
  },
  wrapperCol: {
    span: 14,
  },
};
const tailLayout = {
  wrapperCol: {
    offset: 8,
    span: 14,
  },
};
export default class MachineEditAdd extends Component {
  state = {
    showAddMachine: false,
  };
  addMachineClick = () => {
    this.setState({
      showAddMachine: true,
    });
  };
  closeModel = () => {
    this.setState({
      showAddMachine: false,
    });
  };
  onFinishAddMachine = async (e) => {
    console.log(e);
    this.setState({
      submitLoading: true,
    });
    await this.http("Machine", e, "POST");
    message.success("操作成功！");
    this.setState({
      submitLoading: false,
      showAddMachine: false,
    });
    this.props.refresh();
  };
  render() {
    return (
      <div style={{ display: "inline-block" }}>
        <Modal
          {...layout}
          title=""
          onCancel={this.closeModel}
          footer={[null, null]}
          visible={this.state.showAddMachine}
        >
          <Form name="addMachine" onFinish={this.onFinishAddMachine}>
            <Form.Item
              label="矿机名称"
              name="name"
              rules={[
                {
                  required: true,
                  message: "矿机名称不可为空！",
                },
              ]}
            >
              <Input />
            </Form.Item>
            <Form.Item
              label="矿机英文名称"
              name="name_EN"
              rules={[
                {
                  required: true,
                  message: "矿机英文名称不可为空！",
                },
              ]}
            >
              <Input />
            </Form.Item>
            <Form.Item
              label="矿机种类"
              name="accountCate"
              rules={[
                {
                  required: true,
                  message: "矿机种类不可为空！",
                },
              ]}
            >
              <Radio.Group>
                <Radio value={3}>FIL</Radio>
                <Radio value={5}>CHIA</Radio>
                <Radio value={6}>BZZ</Radio>
                {/* <Radio value={4}>其他</Radio> */}
              </Radio.Group>
            </Form.Item>
            <Form.Item {...tailLayout}>
              <Button
                loading={this.state.submitLoading}
                type="primary"
                htmlType="submit"
              >
                提交
              </Button>
            </Form.Item>
          </Form>
        </Modal>
        <Button
          type="primary"
          className="addBtn"
          onClick={this.addMachineClick}
        >
          新增矿机
        </Button>
      </div>
    );
  }
}
